<?php
session_start();
	require_once "includes/config.php";
	require_once "includes/pagination.php";
    $itemPerPage=10;	
	
	
$curDate = date("Y-m-d G:i:s",time());
		$sqlSelPro="SELECT DISTINCT tbl_items.*, tbl_product.product_name, tbl_product.selling_type, tbl_product.shipping, tbl_users.user_id , tbl_users.username
					FROM tbl_product, tbl_items, tbl_users 
					WHERE tbl_product.product_id = tbl_items.product_id AND 	 	
					 	  tbl_users.user_id=tbl_items.seller_id and tbl_items.product_id='".$_GET['spid']."' and tbl_items.bargain_duration >= '".$curDate."'";
		


	$pLink = "spid=";	
	
	//$pos     = strripos($sqlSelPro, "where");
	//$curDate = date("Y-m-d G:i:s",time());
	//echo $curDate;
	
	//echo $sqlSelP
?>	
<div id='panel'>
<table width="100%" border="0">
  <tr>
    <td class="contentHeader"><h2>Search Results</h2></td>
  </tr>
  <tr>
    <td>

		 <?php 		   
				   
						
				   //echo $sqlSelPro;
				   $rstSelPro=mysql_query($sqlSelPro);			  
				   $num=mysql_num_rows($rstSelPro);				   
				   if($num==0)
					{					
					  	echo "No Products Found...";
					 
					}
				   else { ?>
				   		
					   <br><table width='668' border='0' align='center' cellspacing='0'>
						       <tr>
							   	<td colspan='7'>&nbsp;</td>
							   </tr>
							   <tr class='head-tr'>
								  <td height='26' width='68'>&nbsp;</td>
							      <td width='138'> <strong>Product name </strong></td>
							     <td width='50'><strong>Pickup</strong></td>
							     <td width='90'> <strong>--</strong> </td>
							     <td width='54'> <strong>Price</strong> </td>
						         <td width='57'><strong>Shipping</strong> </td>
						         <td width='197'><strong>Time Left</strong></td>
					     </tr>
						<?php	
						
						 while($rowSelPro=mysql_fetch_array($rstSelPro))
					     {							   
						   $productId=$rowSelPro['product_id'];
						   $itemId=$rowSelPro['item_id'];
						   $productName=wordFormater($rowSelPro['product_name'],20);
						   $productTitle = $rowSelPro['product_name'];					   
						   $productPrice=$rowSelPro['price'];
						   $postedDate=$rowSelPro['posted_date'];
						   $bargainDate = $rowSelPro['bargain_duration'];
						   $timeLeft = getRemainingTime($bargainDate);
						   $shipping = $rowSelPro['shipping'];
						   if($shipping!="Free") {
						   	$shipping = "$".number_format($shipping,2);
						   }
						   
						   $sellType = $rowSelPro['selling_type'];
						   $timeLeft = getRemainingTime($bargainDate);
						   $pimage = getProductImage($itemId,'i');
						   if($pimage['thumb']!="") {
						   		$productThumb = $pimage['thumb'];
						   } else {
						   		$productThumb="images/no_image.gif";	
						   }
						   ?>  
						   <tr>
						        <td height='106'>
						   			<div align='center'><img src='<?php echo $productThumb; ?>'></div>								 </td>								 
								 <td style='vertical-align:top; padding:10px;'> <a href='index.php?products=<?php echo $itemId; ?>' title='<?php echo $productTitle; ?>'> <?php echo $productName; ?> </a> <br /><?php echo $rowSelPro['username'];?> </td>
								 <td style='vertical-align:top; padding:10px;'> <?php echo ucfirst($sellType); ?> </td>
								 <td style='vertical-align:top; padding:10px;'><input type='image' src='images/buy.gif' style='cursor:pointer;' onClick=''></td>
								  <td style='vertical-align:top; padding:10px;'>$<?php echo number_format($productPrice,2); ?> </td>
								 <td style='vertical-align:top; padding:10px;'>  <?php echo $shipping; ?> </td>
						         <td style='vertical-align:top; padding:10px;'><?php echo $timeLeft; ?></td>
						   </tr>	
							   <tr>
									 <td colspan='7'> <div style='border-top:1px solid #CCCCCC;'> </div> </td>
							   </tr>				 	
						 <?php } ?>				 
						</table>
	    <?php } ?>
	
  		<tr>
    		<td><div align="center"><?php
				   $link=$pLink;
				   echo $disp=getPagingLink($sqlSelPro,$itemPerPage,$link);							   
			 ?></div>
			</td>
  		</tr>
 	</table>
	</td>
  </tr>
</table>
</div>